version 18.0               // version control
set processors 8           // to ensure replicability across different numbers of cores
clear all                  // clear existing data
macro drop _all            // and macros, clean slate
set seed 20220909          // set seed

*----------------------------------------------------------------
* Table: Summary Statistics
*----------------------------------------------------------------

local pgm  "dst-Table_2_summary_statistics"                          // file name
local who  "Muzhe Yang"                                              // author
local dte  "2025-01-20"                                              // created date
local dte2 "`c(current_date)'"                                       // last run date
local tag  "`pgm'.do, created by `who' on `dte', last run on `dte2'"

capture log close
log using "code\analysis\tables\\`pgm'.txt", text replace 
display "`tag'"

**# data prep ------------------------------------------------------------------------------------

use "data_clean\dst-data04_for_estimation_within_250_miles", clear
global x "pop white_pct black_pct hispanic_pct pop_under_18yr_pct pop_65yr_over_pct age_median educ_hs_pct educ_coll_pct married_pct hh_size hh_income_median home_value_median no_health_ins_pct unemploy_pct"
local radius = 50
assert !missing(StateAbbr)
egen nomiss = rowmiss($x dist_to_border centroid_lat daylight_dur_max)
gen sample_selection = (nomiss == 0 & StateAbbr != "AZ" & dist_to_border <= `radius')
keep if sample_selection == 1

**# table ---------------------------------------------------------------------------------

dtable depression sleep_depr dental mammo_use hlth_fair_or_poor if wave == 2, ///
       column(summary(, hide)) sample("Number of observations") nformat(%9.3f mean sd) ///
       title("Variables that use Wave II of the PLACES data (prevalence, measured in 0–100)") ///
       name(panel_a) replace 
collect label levels var ///
        depression "Depression" ///
        sleep_depr "Sleeping less than 7 hours" ///
        dental "Dental visit" /// 
        mammo_use "Mammography use" /// 
        hlth_fair_or_poor "Self-rated fair or poor health", modify 

dtable mental_hlth_distress cancer diabetes heart_disease obesity stroke asthma, ///
       column(summary(, hide)) sample("Number of observations") nformat(%9.3f mean sd) ///
       title("Variables that use Wave I and Wave II of the PLACES data (prevalence, measured in 0–100)") ///
       name(panel_b) replace 
collect label levels var ///
        mental_hlth_distress "Mental distress" /// 
        cancer "Cancer" ///
        diabetes "Diabetes" ///
        heart_disease "Heart disease" /// 
        obesity "Obesity" ///
        stroke "Stroke" ///
        asthma "Asthma", modify 

dtable treat dist_to_border centroid_lat daylight_dur_max $x if wave == 2, ///
       column(summary(, hide)) sample("Number of observations") nformat(%9.3f mean sd) ///
       title("Variables that are the same for Wave I and Wave II of the PLACES data") ///
       name(panel_c) replace
collect label levels var ///
        treat "Treat (1/0): 1 for census tracts located east of the time zone border; 0 for census tracts located west of the time zone border" ///
        dist_to_border "Distance between a census tract's centroid and the time zone border (in miles)" ///
        centroid_lat "Latitude of a census tract's centroid" ///
        daylight_dur_max "Maximum of daylight hours per day, county level" ///
        pop "Total population (in 1,000)" ///
        white_pct "Percent of population that is white alone, not Hispanic or Latino (measured in 0–100)" ///
        black_pct "Percent of population that is black alone, not Hispanic or Latino (measured in 0–100)" ///
        hispanic_pct "Percent of population that is Hispanic or Latino (measured in 0–100)" ///
        pop_under_18yr_pct "Percent of population less than 18 years (measured in 0–100)" ///
        pop_65yr_over_pct "Percent of population 65 years or older (measured in 0–100)" ///
        age_median "Median age of the total population" ///
        educ_hs_pct "Percent of population 25 years or older with highest education completed being high school (measured in 0–100)" ///
        educ_coll_pct "Percent of population 25 years or older with highest education completed being bachelor's degree or higher (measured in 0–100)" ///
        married_pct "Percent of population being married (measured in 0–100)" ///
        hh_size "Average household size" ///
        hh_income_median "Median household income in the past 12 months (in $1,000)" ///
        home_value_median "Median home value (for owner-occupied housing units, in $1,000)" ///
        no_health_ins_pct "Percent of population with no health insurance coverage (measured in 0–100)" ///
        unemploy_pct "Percent of population being unemployed (measured in 0–100)", modify 

collect export "code\analysis\tables\\`pgm'.xlsx", name(panel_a) sheet("Panel A", replace) replace
collect export "code\analysis\tables\\`pgm'.xlsx", name(panel_b) sheet("Panel B", replace) modify
collect export "code\analysis\tables\\`pgm'.xlsx", name(panel_c) sheet("Panel C", replace) modify

log close
exit